using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Core.Mapping;
using WorldEditor.Properties;

namespace WorldEditor
{
    public partial class MapLayers : UserControl
    {
        public event EventHandler SelectedLayerChanged;

        public MapLayers()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            LoadPropertyGrid();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        public void LoadPropertyGrid()
        {
            //---Add Map Layers to Layers List---//
            dgvLower.Rows.Clear();

            dgvLower.Rows.Add();
            dgvLower.Rows[0].Cells["NameLower"].Value = "Base";

            dgvLower.Rows.Add();
            dgvLower.Rows[1].Cells["NameLower"].Value = "Terrain";

            dgvLower.Rows.Add();
            dgvLower.Rows[2].Cells["NameLower"].Value = "Terrain Detail";

            dgvLower.Rows.Add();
            dgvLower.Rows[3].Cells["NameLower"].Value = "Terrain Super Detail";

            RemoveAllDataGridSelections();

            dgvLower.Rows[0].Selected = true;
        }

        private void UnselectAllRowsInGrid(DataGridView dgv)
        {
            foreach (DataGridViewRow dgvr in dgv.Rows)
            {
                dgvr.Selected = false;
            }
        }

        private void RemoveAllDataGridSelections()
        {
            UnselectAllRowsInGrid(dgvLower);
        }


        private void dgvLower_SelectionChanged(object sender, EventArgs e)
        {
            if (SelectedLayerChanged != null && dgvLower.SelectedRows.Count > 0)
            {
                MapLayerTypes tmlt = new MapLayerTypes();

                switch (dgvLower.SelectedRows[0].Index)
                {
                    case 0: tmlt = MapLayerTypes.Base; break;
                    case 1: tmlt = MapLayerTypes.Terrain; break;
                    case 2: tmlt = MapLayerTypes.TerrainDetail; break;
                    case 3: tmlt = MapLayerTypes.TerrainSuperDetail; break;
                }

                SelectedLayerChanged.Invoke(tmlt, null);
            }
        }

        private void Lower_Paint(object sender, PaintEventArgs e)
        {
            Rectangle rectEye = new Rectangle(6, 3, 12, 12);
            e.Graphics.DrawImage(Resources.eye, rectEye);
            
            Rectangle rectLock = new Rectangle(25,3,14,14);
            e.Graphics.DrawImage(Resources.Lock,rectLock);
        }
    }
}
